package com.zmn.plat.utils.callback;

import com.zmn.plat.services.interfaces.channel.ChannelService;
import com.zmn.plat.utils.bean.SpringBeanUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.util.CollectionUtils;

import java.util.List;
import java.util.Objects;
import java.util.function.Predicate;

/**
 * @author tanbiao
 * @description
 * @modifier
 * @since 2020/11/12 10:01
 **/
@Slf4j
public class CallbackUtils {
    private static ChannelService channelService = SpringBeanUtils.getBean(ChannelService.class);

    /**
    * 描述：针对集合的处理
    * @param callback
    * @param channelId
    * @author tanbiao
    * @since 2020/11/12 10:17
    * @return T
    * @modifier      
    */
    public static  <T> T executeList(Callback<T,ChannelService> callback, Integer channelId) {
        Predicate<List> predicate= x->CollectionUtils.isEmpty(x);
        return callback.doCallback(channelId,channelService,predicate,log);
    }

    /**
     * 描述：针对单个实体的处理
     * @param callback
     * @param channelId
     * @author tanbiao
     * @since 2020/11/12 10:17
     * @return T
     * @modifier
     */
    public static  <T> T execute(Callback<T,ChannelService> callback, Integer channelId) {
        Predicate<T> predicate= x-> Objects.isNull(x);
        return callback.doCallback(channelId,channelService,predicate,log);
    }


    /**
     * 描述：针对自定义的处理，重写Predicate
     * @param callback
     * @param channelId
     * @author tanbiao
     * @since 2020/11/12 10:17
     * @return T
     * @modifier
     */
    public static  <T> T execute(Callback<T,ChannelService> callback,Predicate<T> predicate, Integer channelId) {
        return callback.doCallback(channelId,channelService,predicate,log);
    }
}
